<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="tld" uri="/WEB-INF/tld/rei.tld" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib
		prefix="c"
		uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>个人信息</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/static/css/oksub.css">
	<script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<input type="hidden" name="id" value="${model.id}">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="username" value="${model.username}" readonly  autocomplete="off" class="layui-input" lay-verify="required">
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="password" name="password" placeholder="密码不改则无需输入" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">昵称</label>
			<div class="layui-input-block">
				<input type="text" name="name" placeholder="请输入昵称" autocomplete="off" value="${model.name}" class="layui-input" lay-verify="required">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">头像</label>
			<div class="layui-input-inline">
				<img src="/admin/attachment/image/${model.photo}" name="image" width="80px;">
				<input name="photo" value="${model.photo}" type="hidden"/>
			</div>
			<div class="layui-input-inline layui-btn-container" style="width: auto;">
				<button type="button" class="layui-btn layui-btn-primary" id="upload">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>

			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">角色</label>
			<div class="layui-input-block">
				<select name="role">
					<c:if test="${model.type eq 0}">
						<option value="0">会员</option>
					</c:if>
					<c:if test="${model.type eq 1}">
						<option value="1">管理员</option>
					</c:if>
				</select>

			</div>

		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">年龄</label>
			<div class="layui-input-block">
				<input type="number" value="${model.age}" name="age" placeholder="请输入年龄" autocomplete="off"
					   class="layui-input" id="age" >
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block">
				<input type="radio" name="sex" value="男" title="男"  <c:if test="${model.sex eq '男'}">checked</c:if>>
				<input type="radio" name="sex" value="女" title="女" <c:if test="${model.sex eq '女'}">checked</c:if>>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script><script src="/static/js/jquery.min.js"></script>
<script src="/static/js/jquery.min.js"></script>
<script>
	layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		okLoading.close();
		laydate.render({elem: "#birthday", type: "datetime"});

		form.verify({
			birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
		});

		form.on("submit(add)", function (data) {
			okUtils.ajax("/admin/user/save", "post", data.field, true).done(function (response) {
				layer.alert("成功", {icon: 6}, function (index) {
					layer.close(index);
				});
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});
		//上传
		layui.use('upload', function () {
			var upload = layui.upload;
			//执行实例
			var uploadInst = upload.render({
				elem: '#upload' //绑定元素
				, url: '/files/upload' //上传接口
				, done: function (res) {
					//上传完毕回调
					$("img[name=image]").attr("src", "/admin/attachment/image/"+res.data.id);
					$("input[name=photo]").val(res.data.id);
				}
				, error: function () {
					//请求异常回调
					layer.alert("上传失败", {icon: 5});
				}
			});
		});
	});
</script>
</body>
</html>
